package top.aigoo.project01.utils;

/**
 * @Description: 根据不同的操作系统获取不同根路径
 * @Author: Mr.OYSHUO.欧阳大叔  mail:1642302522@qq.com
 * @Version 1.0.0
 * @Date: 2021/8/8 22:37
 */
public class PathUtil {
    //获取当前系统的文件分隔符
    private static String seperator = System.getProperty("file.separator");

    /**
     * 为什么不将图片保存在src/main/resource下面？ 因为如果放到src/main/resource下面，那么用户每次上传照片，服务器重启后，这些图片
     * 就找不到了
     *
     * @return 存储图片的根路径
     */
    public static String getImgBasePath() {
        String os = System.getProperty("os.name");
        String basePath = "";
        if (os.toLowerCase().startsWith("win")) {
            basePath = "G:/baidu/project01_o2o/images/";
        } else {
            basePath = "/home/oyshuo/project01_o2o/images/";
        }
        basePath = basePath.replace("/", seperator);
        return basePath;
    }

    /**
     * 获取店铺图片的存储路径
     */
    public static String getShopImagePath(long shopId) {
        StringBuilder shopImagePathBuilder = new StringBuilder();

        shopImagePathBuilder.append("/upload/images/item/shop/");

        shopImagePathBuilder.append(shopId);

        shopImagePathBuilder.append("/");

        String shopImagePath = shopImagePathBuilder.toString().replace("/", seperator);

        return shopImagePath;
    }

    public static String getPersonInfoImagePath() {

        String personInfoImagePath = "/upload/images/item/personinfo/";
        personInfoImagePath = personInfoImagePath.replace("/", seperator);
        return personInfoImagePath;
    }
}
